﻿;(function($,undefined){
	$.fn.seleteCity = function(options){
		var opts = {
			trigger : "focus",			//触发事件		
			language : 1,				//中英文判断	
			popUrl : "./selectPop.html",	//绝对路径：http://i.zhaopin.com/content/city/selectPop.html
			isArea	: true,				//是否显示区
			isMultipleChoice : false,	//是否为多选
			isForeign : false,			//是否有海外选项
			isForeignList : false,		//是否有海外具体的列表项
			closeCallback : null,		//关闭前的回调
			limit : 3			//地点最大可选个数
		};
		$.variate = {
			popWrap : null,
			tab : null,
			tabIndex : null,
			citylist : null,
			selectHK : null,
			closebtn : null,
			topTitle : null,
			firstTab : null,
			hotCity : null,
			province : null,
			selectedTitle : null,
			surebtn : null,
			tabPcon : null,
			tabACon : null,
			tabHKCon : null,
			selectedList : null,
			tabArea : null,
			tabHK : null,
			tabProvince : null
		};
		var hotcityData,cityData,areaData,tipMap,imgsrc,message;  //保存数据的变量
		var selector = this.selector;
		$.extend(opts,options);
		var utils = {

			creatPop : function(obj){
				var pop = $("#selectCityPop").length;   //第一次加载弹出框
				if(  pop == 0 ){
					$.ajax({
						url : opts.popUrl,
						dataType : "html",
						async: false, 
						success : function(data){							
 							var selectJobCate = new ZPIDC.dialog({
                   				ontainerid: "selectCityPop",//自定义的id属性
                    			containerCls : 'window_container_border',//容器最外框样式
                   				headerHeight : '0px'//头高度
                			});
                			selectJobCate.optionBody(data);
							utils.creatDom();															
							utils.deleteCity();							
							utils.listStyle();														
						}
					});
				}else{										
					$.variate.popWrap.show();
					$(".global-mask-container").show();					
					$.variate.tab.find("li").hide();
					$.variate.tabIndex.show().siblings().hide();
					$.variate.citylist.html("");
					$.variate.selectHK.find("span").removeClass("active");				
				}				
				utils.init(obj);				
			},
			init : function(obj){
				
				utils.languageFun();
				utils.setText();
				utils.reverse(obj);
				utils.activeSetting();
				$.variate.closebtn.unbind("click").bind("click",function(){
					utils.closePop();
				});
				utils.sureBtn(selector);
				utils.creatListIndex();	
				utils.selected();
				utils.highLight();
				utils.selecteList();

				setTimeout(function(){
					// ie6下控件位置
				        //if ('undefined' == typeof(document.body.style.maxHeight)){//ie6 浏览器
				            var h1 = (document.documentElement.clientHeight||document.body.clientHeight)/2;
				            var h2 = document.body.scrollTop || document.documentElement.scrollTop;
				            $("#window_container").css("top",h1+h2);
				        //}
		    		},10)
			},
			selecteList : function(){		//选择项的列表是否显示
				var flag = $.variate.selectedList.find("li").length;  
					if( !flag ){
						$.variate.selectedList.siblings().hide();
					}else{
						$.variate.selectedList.siblings().show();
					}
			},
			setText : function(){   //弹框的文字
				$.variate.topTitle.find("span").text(tipMap.popTitle);
				if($.variate.topTitle.find('small').length == 0 && opts.isMultipleChoice){
					$.variate.topTitle.append('<small>' + tipMap.max5 +'</small>')
				}
				$.variate.firstTab.text(tipMap.tab1);
				$.variate.tab.find("li").eq(2).text(tipMap.tab4).removeClass("nocurrent").siblings().addClass("nocurrent");
				$.variate.hotCity.prev("h2").text(tipMap.hotCity);
				$.variate.province.prev("h2").text(tipMap.tab2);
				$.variate.selectHK.find("span").text(tipMap.tab4);
				$.variate.selectedTitle.text(tipMap.selected);
				$.variate.surebtn.val(tipMap.sureBtn);
				$.variate.closebtn.val(tipMap.closeBtn);
			},
			
			languageFun : function(){
				if( opts.language == 1 ){
					hotcityData = hotCity;
					cityData = city;
					areaData = CONST_DISTRICT;
					tipMap = {
						popTitle : "选择城市信息",
						max5 : '最多可选' + opts.limit + '项',
						tab1 : "全部",
						tab2 : "省份",
						tab3 : "地区",
						tab4 : "海外",
						hotCity : "热门城市",
						selected : "您当前的选择:",
						sureBtn : "确定",
						closeBtn : "取消"
					}
					imgsrc = "http://img01.zpin.net.cn/2014/c/img/creat_resume/qu.jpg";
					message = "不能超过" + opts.limit + "项";
				}else{
					hotcityData = hotCity_en;
					cityData = city_en;
					areaData = CONST_DISTRICT_en;
					tipMap = {
						popTitle : "Please select city",
						max5 : 'Most selection ' + opts.limit,
						tab1 : "All",
						tab2 : "Provice",
						tab3 : "Area",
						tab4 : "OVERSEAS",
						hotCity : "Hot",
						selected : "Your selection:",
						sureBtn : "OK",
						closeBtn : "Cancel"
					}
					imgsrc = "http://img01.zpin.net.cn/2014/c/img/creat_resume/district.jpg";
					message = "No more than " + opts.limit;
					$("#selectCityPop").addClass("style_en");
				};
			},		
			reverse :function( obj ){   //反向赋值
				if(opts.isMultipleChoice){						
					 utils.multipeValue(obj);
				}else{
					var selectedVal = obj.val(),
					 	pid =  obj.next().val(),
						cid =  obj.next().next().val(),
						aid =  obj.next().next().next().val();
					utils.evaluation($(this),selectedVal,pid,cid,aid);
				}	
			},	
			creatList : function( value , pid , cid , aid ){   //文字的长度判断 
				var flag,list;
				cid = cid ? cid : (cid = pid);
				if( opts.language != 1 ){
					flag = value.length > 11 ? true : false; 
				}else{
					flag = value.length > 8 ? true : false; 
				}
				if( flag ){
					if(aid){
						list = "<li class=\"listsp\" data-p="+pid+" data-c="+cid+" data-a="+aid+"><span>"+value+"</span></li>"
					}else{
						list = "<li class=\"listsp\" data-p="+pid+" data-c="+cid+"><span>"+value+"</span></li>"
					}			
				}else{
					if(aid){
						list = "<li  data-p="+pid+" data-c="+cid+" data-a="+aid+"><span>"+value+"</span></li>"
					}else{
						list = "<li  data-p="+pid+" data-c="+cid+"><span>"+value+"</span></li>"
					}	
				}
				return list;
			},
			creatListIndex : function(){  
				for( var i = 0 ; i < hotcityData.length ; i++ ){   //热门城市列表
					for( var j = 0; j < hotcityData[i].sub.length; j++ ){	
						if( hotcityData[i].id == "489" ){
							$.variate.hotCity.append(utils.creatList(hotcityData[i].sub[j].value,hotcityData[i].sub[j].id,hotcityData[i].sub[j].id));
						}else{
							if( hotcityData[i].sub[j].id !="654" && hotcityData[i].sub[j].id !="636" && hotcityData[i].sub[j].id !="768" && hotcityData[i].sub[j].id !="773" && hotcityData[i].sub[j].id !="707")
							$.variate.hotCity.append(utils.creatList(hotcityData[i].sub[j].value,hotcityData[i].id,hotcityData[i].sub[j].id));
						}					
											
					}	
				};
				utils.isAreaFun($.variate.hotCity);
				for( var i = 0; i < cityData[0].sub.length;i++ ){ //省份列表
					if( cityData[0].sub[i].id !== "530" && cityData[0].sub[i].id !== "538" && cityData[0].sub[i].id !== "531" && cityData[0].sub[i].id !== "551"  ){
						$.variate.province.append(utils.creatList(cityData[0].sub[i].value,cityData[0].sub[i].id));
					}					
				};
				if( opts.isForeign || opts.isForeignList ){
					$.variate.province.append("<li class=\"j_selectHK\" data-p=\"480\" data-c=\"480\"><span>"+tipMap.tab4+"</span></li>");
				};				
			},
			creatCity : function( sId ){	//市列表
				$.variate.tabPcon.find("li").remove();
				for( var i = 0; i < cityData[0].sub.length;i++ ){
					if( sId == cityData[0].sub[i].id ){
						for( var j = 0 ; j < cityData[0].sub[i].sub.length; j ++ ){
							$.variate.tabPcon.append(utils.creatList(cityData[0].sub[i].sub[j].value,cityData[0].sub[i].id,cityData[0].sub[i].sub[j].id))							
						}
					}
				}
				utils.isAreaFun($.variate.tabPcon);
			},
			creatArea :function( pValue,acid){  //区列表
				$.variate.tabACon.find("li").remove();
				for( var i = 0; i< areaData.length;i++ ){
					if( pValue == areaData[i].value ){
						for( var j = 0 ;j < areaData[i].sub.length; j ++ ){
							$.variate.tabACon.append(utils.creatList(areaData[i].sub[j].value,acid,areaData[i].id,areaData[i].sub[j].id))
						}
					}
				}
			},
			creatForeign : function(){  //海外列表
				for(var i = 0;i < cityData[1].sub.length;i++ ){
					$.variate.tabHKCon.append(utils.creatList(cityData[1].sub[i].value,cityData[1].id,cityData[1].sub[i].id))
				}	
			},
			isAreaFun : function(obj){  //区图标的显示
				if(opts.isArea){
					obj.find("li").each(function(){
						var cid = $(this).attr("data-c");
						for ( var i =  0; i < areaData.length; i++ ){
							if( cid == areaData[i].id ){
								$(this).append("<img src="+imgsrc+" />");
							}							
						};						
					})
				}
			},
			maxFiveFun : function(){	// 已选项的个数，超过不可选			
				if(opts.isMultipleChoice){
					if( $.variate.selectedList.find("li").length > opts.limit - 1 ){
						if($(".j_errorTips").length == 0){
							$.variate.selectedList.append("<div class=\"j_errorTips\">"+message+"</div>");
						}
						return false;
					}
					return true;
				}else{
					return true;
				}
				
			},
			evaluation : function( obj,sValue,pid,sid,aid ){ //点击赋值到已选标签
				sid = sid ? sid : (sid = pid);		
				if(sValue){
					if( !obj.find("span").hasClass("active") ){
						if( opts.isMultipleChoice ){												
							$("<li>"+sValue+"<a class=\"closeCity j_deleteCity\"></a></li>").appendTo($.variate.selectedList).attr({"data-p":pid,"data-c":sid,"data-a":aid});																		
						}else{
							$.variate.selectedList.html("");					
							$.variate.selectedList.append("<li>"+sValue+"<a class=\"closeCity j_deleteCity\"></a></li>").find("li").attr({"data-p":pid,"data-c":sid,"data-a":aid});	
						}
					}
				}else{
					$.variate.selectedList.html("");
				}				
			},
			multipeValue :function( sValue ){   //多选的反向赋值 
				$.variate.selectedList.html("");				
				var arrId = sValue.next().val().split(","),
					pid,cid,aid,pval,cval,aval,flag,areaArr;

				for ( var i = 0 ; i < arrId.length; i++ ){
					flag = false;
					areaArr = arrId[i].split(":");
					if( areaArr.length == 2 ){
						arrId[i] = areaArr[1];
			
					}
					for( var j = 0 ; j < cityData[1].sub.length ; j ++ ){
						if( arrId[i] == cityData[1].sub[j].id ){
							pid = cityData[1].id;
							pval = cityData[1].sub[j].value;
							cid = cityData[1].sub[j].id;
							flag = true;
							$("<li>"+pval+"<a class=\"closeCity j_deleteCity\"></a></li>").appendTo($.variate.selectedList).attr({"data-p":pid,"data-c":cid,"data-a":aid});	
						}
					}
					for( var j = 0; j < cityData[0].sub.length;j++ ){
						if( arrId[i] == cityData[0].sub[j].id ){
							pid = cityData[0].sub[j].id;
							pval = cityData[0].sub[j].value;
							flag = true;
							cid = pid;
							$("<li>"+pval+"<a class=\"closeCity j_deleteCity\"></a></li>").appendTo($.variate.selectedList).attr({"data-p":pid,"data-c":cid,"data-a":aid});						
						}else{
							if( cityData[0].sub[j].sub ){
								for( var m = 0;m<cityData[0].sub[j].sub.length;m++ ){
									if( arrId[i] == cityData[0].sub[j].sub[m].id ){
										pid = cityData[0].sub[j].id;
										pval = cityData[0].sub[j].value;
										cid = cityData[0].sub[j].sub[m].id;
										cval = cityData[0].sub[j].sub[m].value;
										flag = true;
										$("<li>"+cval+"<a class=\"closeCity j_deleteCity\"></a></li>").appendTo($.variate.selectedList).attr({"data-p":pid,"data-c":cid,"data-a":aid});
										break;
									}
								}
							}
						}								
					}
					if( !flag ){
						
						for ( var m = 0; m <areaData.length;m++ ){
							for( var n = 0; n<areaData[m].sub.length;n++ ){
								if( arrId[i] == areaData[m].sub[n].id ){
									for( var k = 0; k < cityData[0].sub.length;k++ ){
										if(cityData[0].sub[k].sub){
											for( var x = 0; x < cityData[0].sub[k].sub.length;x++ ){
												if( cityData[0].sub[k].sub[x].id == areaData[m].id ){
													pid = cityData[0].sub[k].id;	
												}
											}
										}
									}
									cid = areaData[m].id;
									aid = areaData[m].sub[n].id;
									aval = areaData[m].value +"-"+ areaData[m].sub[n].value;
									if( cid != 530 || cid != 538 || cid != 531 || cid != 551 ){
										pid = cid;
										$("<li>"+aval+"<a class=\"closeCity j_deleteCity\"></a></li>").appendTo($.variate.selectedList).attr({"data-p":pid,"data-c":cid,"data-a":aid});	
									}
									
								}
							}
						}
					}
				}
			},
			highLight : function(){  //反向赋值的active状态
				$.variate.province.find("li").each(function(){
					var thisObj = $(this);					
					$.variate.selectedList.find("li").each(function(){
						if( thisObj.attr("data-p") == $(this).attr("data-p") ){	
							thisObj.find("span").addClass("active");
						}
					})		
				});
				$.variate.hotCity.find("li").each(function(){
					var thisObj = $(this);	
					$.variate.selectedList.find("li").each(function(){
						if( thisObj.attr("data-p") == $(this).attr("data-p") && thisObj.attr("data-c") == $(this).attr("data-c") ){							
							thisObj.find("span").addClass("active");
						}
					})					
				})
			},
			selected : function(){
				$.variate.firstTab.click(function(){ //点击全部
					utils.activeSetting();
					$.variate.tab.find("li").hide();
					$.variate.tabIndex.show().siblings().hide();
				});
				$.variate.tab.find("li").eq(0).click(function(){ //点击省
					$(this).removeClass("nocurrent");
					if( $(this).next().css("display") !== "none" ){
						var pid = $(this).attr("data-p"),
							pValue ;
						if($(this).next()){
							$(this).next().hide();
							$.variate.tabArea.hide();
						}
						for( var i  = 0 ; i < cityData[0].sub.length ; i ++ ){
							if(cityData[0].sub[i].sub){
								for( var j = 0 ; j < cityData[0].sub[i].sub.length ; j++ ){
									if( cityData[0].sub[i].id == pid ){
										pValue = cityData[0].sub[i].value;
									}
								}
							}
						}
						$.variate.tabProvince.show().siblings().hide();
						$.variate.tabProvince.find("h3").text(pValue);
						utils.creatCity(pid);
						utils.activeSetting();
					} 
										
				});
				$.variate.hotCity.off("click","li").on("click","li",function(){ //点击热门城市
					var sValue = $(this).text(),
						pid = $(this).attr("data-p"),
						sid = $(this).attr("data-c"),
						aid = $(this).attr("data-a");
						if( !$(this).find("span").hasClass("active") ){
							if( utils.maxFiveFun() ){
								utils.evaluation($(this),sValue,pid,sid,aid);
								if(opts.isMultipleChoice){	
									utils.conditions(pid,sid,aid);
								}	
								utils.activeSetting();
								utils.selecteList();
							}	
						}										
							
				});
				$.variate.hotCity.off("click","img").on("click","img",function(){ //点击热门城市的区
					var pValue = $(this).parent().text();
					var acid = $(this).parent().attr("data-p"),
						accid = $(this).parent().attr("data-c");
					$.variate.tab.find("li").eq(1).text(pValue).show().removeClass("nocurrent").siblings().addClass("nocurrent");
					$.variate.tabArea.show().siblings().hide();
					utils.creatArea(pValue,acid);
					$.variate.tabArea.find("h3").text(pValue).attr({"data-p":acid,"data-c":accid});
					utils.activeSetting();
					return false;
				});
				$.variate.province.off("click","li").on("click","li",function(){ //点击省列表
					var pValue = $(this).text(),
						pid = $(this).attr("data-p"),
						sid = $(this).attr("data-c"),
						aid = $(this).attr("data-a");
					if( utils.maxFiveFun() ){						
							if( pid !== "561" && pid !== "562" && pid !== "563" && pid !== "480"){
								$.variate.tab.find("li").eq(0).text(pValue).attr("data-p",pid).show().removeClass("nocurrent").siblings().addClass("nocurrent");
								$.variate.tabProvince.show().siblings().hide();
								$.variate.tabProvince.find("h3").text(pValue).attr({"data-p":pid,"data-c":sid});
								utils.creatCity(pid);
							}else if( pid === "480" ){
								 if(opts.isForeignList){												
										$.variate.tabHK.show().siblings().hide();
										$.variate.tab.find("li").eq(2).show();
										if( $.variate.tabHK.find("li").length == 0 ){
											utils.creatForeign();
										};															
								}
							}
							
						if( !$(this).find("span").hasClass("active") ){						
							utils.evaluation($(this),pValue,pid,sid,aid);						
							if(opts.isMultipleChoice){
								utils.conditions(pid,sid,aid);
							}
							
							utils.selecteList();
						}
						utils.activeSetting();
					}
				});
				$.variate.tabHKCon.off("click","li").on( "click","li",function(){		//海外
						var sValue = $(this).text(),
						pid = $(this).attr("data-p"),
						sid = $(this).attr("data-c"),
						aid = $(this).attr("data-a");	
						if( utils.maxFiveFun() ){					
							utils.evaluation($(this),sValue,pid,sid,aid);
							
							if(opts.isMultipleChoice){
								utils.conditions(pid,sid,aid);
							}
							utils.activeSetting();
							utils.selecteList();
						}
											
				});	
				$.variate.tabProvince.off("click","li").on("click","li",function(){		//市
					var sValue = $(this).text(),
						pid = $(this).attr("data-p"),
						sid = $(this).attr("data-c"),
						aid = $(this).attr("data-a");
						if( utils.maxFiveFun() ){
							utils.evaluation($(this),sValue,pid,sid,aid);
							
							if(opts.isMultipleChoice){
								utils.conditions(pid,sid,aid);
							}
							utils.activeSetting();
							utils.selecteList();
						}	
				});
				$.variate.tabProvince.off("click","img").on("click","img",function(){		//市傍边区
					var pValue = $(this).parent().text();
					var acid = $(this).parent().attr("data-p")
						accid = $(this).parent().attr("data-c");
					$.variate.tab.find("li").eq(1).text(pValue).show().removeClass("nocurrent").siblings().addClass("nocurrent");
					$.variate.tabArea.show().siblings().hide();
					utils.creatArea(pValue,acid);
					$.variate.tabArea.find("h3").text(pValue).attr({"data-p":acid,"data-c":accid});
					utils.activeSetting();
					return false;
				});
				$.variate.tabArea.off("click","li").on("click","li",function(){		//区
					var sValue = $(this).parent().prev("div").find("h3").text()+"-"+$(this).text(),
						pid = $(this).attr("data-p"),
						sid = $(this).attr("data-c"),
						aid = $(this).attr("data-a");
						if( utils.maxFiveFun() ){
							utils.evaluation($(this),sValue,pid,sid,aid);							
							if(opts.isMultipleChoice){
								utils.conditions(pid,sid,aid);
							}
							utils.activeSetting();
							utils.selecteList();
						}					
				});
				$.variate.tabProvince.off("click","h3").on("click","h3",function(){  //点击省下的h3
					if(!$(this).hasClass("active")){
						var sValue = $(this).text(),
						 	pid = $(this).attr("data-p"),
							sid = $(this).attr("data-c"),
							aid = $(this).attr("data-a");
						if( utils.maxFiveFun() ){
							$(this).addClass("active");
							utils.evaluation($(this),sValue,pid,sid,aid);
							if(opts.isMultipleChoice){
								utils.conditions(pid,sid,aid);
							}
							utils.activeSetting();
							utils.selecteList();
						}
					}
				});
				$.variate.tabArea.off("click","h3").on("click","h3",function(){ //点击市下的h3
					if(!$(this).hasClass("active")){
						var sValue = $(this).text(),
						 	pid = $(this).attr("data-p"),
							sid = $(this).attr("data-c"),
							aid = $(this).attr("data-a");
						if( utils.maxFiveFun() ){
							$(this).addClass("active");
							utils.evaluation($(this),sValue,pid,sid,aid);
							if(opts.isMultipleChoice){
								utils.conditions(pid,sid,aid);
							}
							utils.activeSetting();
							utils.selecteList();
						}
					}
				});
			},
			conditions : function( pid,cid,aid){  //互斥条件
				if($.variate.selectedList.find("li").length > 0){
					$.variate.selectedList.find("li").each(function(){
						var lpid = $(this).attr("data-p"),
							lcid = $(this).attr("data-c"),
							laid = $(this).attr("data-a");
						if(aid){
							if(!laid){
								if(lpid != lcid ){
									if( lcid == cid && !laid ){
										$(this).remove();
									}
								}else{
									if(pid == lpid){
										$(this).remove();
									}
								}
							}
						}else{
							if( pid != cid ){
								if( lpid == lpid&&lcid == cid &&  laid ){
									$(this).remove();
								}else{
									if(lpid == lcid){
										if( pid == lpid ){
											$(this).remove();
										}
									}
								}
							}else{
								if(pid == lpid){
									if( lpid != lcid ){
										$(this).remove();
									}
									// if(laid){
									// 	if(  cid == lcid && laid != aid  ){
									// 		$(this).remove();
									// 	}
									// }else{
									// 	if(  cid != lcid ){
									// 		$(this).remove();
									// 	}
									// }
									
								}
							}
						}
					});
				}
					
			},
			activeSetting : function(){  //添加选中状态
				$.variate.citylist.find("li").each(function(){
					var lpid = $(this).attr("data-p"),
						lcid = $(this).attr("data-c"),
						laid = $(this).attr("data-a"),
						thisObj = $(this);
					if(laid){		//遍历的citylist是区
						var flag = true;
						$.variate.selectedList.find("li").each(function(){
							var pid = $(this).attr("data-p"),
								cid = $(this).attr("data-c"),
								aid = $(this).attr("data-a");
							if(laid == aid){
								thisObj.find("span").addClass("active");
								flag = false;
							}
						});
						if(flag){
							thisObj.find("span").removeClass("active");
						}
					}else{
						if(lpid != lcid){			//市
							var flag = true;
							$.variate.selectedList.find("li").each(function(){
								var pid = $(this).attr("data-p"),
									cid = $(this).attr("data-c"),
									aid = $(this).attr("data-a");
								if(lcid == cid){
									thisObj.find("span").addClass("active");
									flag = false;
								}
							});
							if(flag){
								thisObj.find("span").removeClass("active");
							}
						}else{
							var flag = true;
							$.variate.selectedList.find("li").each(function(){
								var pid = $(this).attr("data-p"),
									cid = $(this).attr("data-c"),
									aid = $(this).attr("data-a");
								if(lpid == pid){
									thisObj.find("span").addClass("active");
									flag = false;
								}
							});
							if(flag){
								thisObj.find("span").removeClass("active");
							}
						}
					}
				});
				utils.titleActive();
			},
			titleActive: function(){		//h3的互斥		
					var flag = true;
					$(".j_tabContent").find("h3").each(function(){
						var thisObj = $(this),
							lpid = thisObj.attr("data-p"),
							lcid = thisObj.attr("data-c"),
							laid = thisObj.attr("data-a");
						$.variate.selectedList.find("li").each(function(){
							var pid = $(this).attr("data-p"),
								cid = $(this).attr("data-c"),
								aid = $(this).attr("data-a");
								if( pid == lpid && cid == lcid && laid == aid ){
									thisObj.addClass("active");
									flag = false;
								}	
						})
						if(flag){
							thisObj.removeClass("active");
						}
					})
				
				
			},
			listStyle : function(){	 //划过效果
				$(".j_tabContent").off("mouseover mouseout","h3").on({
						mouseover:function(){							
							$(this).addClass("hover");				
						},mouseout:function(){						
							$(this).removeClass("hover");
						}
				},"h3")
				$.variate.citylist.off("mouseover mouseout","li").on({
						mouseover:function(){							
							$(this).find("img").show().end().find("span").addClass("hover");				
						},mouseout:function(){						
							$(this).find("img").hide().end().find("span").removeClass("hover");
						}
				},"li")
			},
			sureBtn : function(selector){  //确定按钮
				$.variate.surebtn.off("click").on("click", function(){
					var obj = $(selector);					    
					if(opts.isMultipleChoice){
						var arr = [],
						    mval = "",
						    valId = "",
						    arrId = [],
						    areaID;
						$.variate.selectedList.find("li").each(function(){
							arr.push($(this).text());
							if( $(this).attr("data-a") ){
								areaID = $(this).attr("data-c")+":"+$(this).attr("data-a")
								arrId.push( areaID );						
							}else if( $(this).attr("data-p") != $(this).attr("data-c") ){
								arrId.push( $(this).attr("data-c") );
							}else{
								arrId.push( $(this).attr("data-p") );
							}							
						})
						mval = arr.join("；");
						valId = arrId.join(",")
						obj.val(mval);
						obj.next().val(valId);

					}else{
						obj.val($.variate.selectedList.find("li").text());
						obj.next().val($.variate.selectedList.find("li").attr("data-p"))
						obj.next().next().val($.variate.selectedList.find("li").attr("data-c"))
						obj.next().next().next().val($.variate.selectedList.find("li").attr("data-a"))						
					}
					utils.closePop();
				});
			},
			closePop: function(){  //取消按钮
				$.variate.popWrap.hide();
				$(".global-mask-container").hide();
				if(opts.closeCallback){
					opts.closeCallback();
				}				
			},
			deleteCity : function(){  //标签取消事件
				$.variate.selectedList.on("click","li",function(){					
					$(this).remove();
					utils.activeSetting();					
					utils.selecteList();
					if($(".j_errorTips").length != 0){
						$(".j_errorTips").remove();
					}
				})
			}
		};
		
		$(document).off(opts.trigger).on(opts.trigger, this.selector ,function(){
			utils.creatPop($(this));
		})
	}
})(jQuery)